<?php

include_once ('Wechat.php');

$options = array(
    'token' => "o5Dttg7seGr7n8G8bu3r", //$config["token"], // 填写你设定的key
    'encodingaeskey' => 'IZqYmURuhaEThWh4D9GEqR08ILWfwe0PVal5AJ7IyxD', // 填写加密用的EncodingAESKey
    'appid' =>'wx33ef06b1e938bc90',// 'wx32e0fc7be8ddb657', // 填写高级调用功能的app id
    'appsecret' => '54430d3098cc56c1e270b39cbd0db067',//eb2d791c55d371b103aaf2d8a8dd36f4', // 填写高级调用功能的密钥
    'debug' => true
);
$wechat = new Wechat($options);

/*
 * http://www.shjieta.com.cn/shop/plugin/Wechat/action.php?get=valid
 * weixin server validation
 */
if ($_GET["get"] == "valid") {
    $wechat->valid();
    exit;
}

/*
 * weixin get token
 */
if ($_GET["get"] == "token") {
    $result = $wechat->checkAuth();
    exit;
}


/*
 * weixin get token
 */
if ($_GET["get"] == "Oauth") {

    $code = isset($_GET['code']) ? $_GET['code'] : '';
    if (!$code) {
        $url = 'http://www.shjieta.com.cn/shop/plugin/Wechat/action.php?get=Oauth';
        $result = $wechat->getOauthRedirect($url, '111','SCOPE');
        header("location: ".$result); 
        exit; 
    } else {
        $result = $wechat->getOauthAccessToken();
        echo $result;
    }

    exit;
}
?>